﻿<?php require_once('../wp-blog-header.php'); ?>
<?php get_header(); ?>
<SCRIPT type=text/javascript src="javascripts.js"></SCRIPT>
<?php
	// require_once('checkSession.php');
	require_once('conn.php');

	$searchMobileNO = "*";
	if ($searchMobileNO=="*")
	{
		$exec="select * from buyRecord order by buyDate DESC";
	}
	else
	{		
		$exec="select * from buyRecord where mobileNO='".$searchMobileNO."' order by name DESC, buyDate DESC";
	}	
	$result=mysql_query($exec);
	if (mysql_num_rows($result) < 1)
	{
		echo '<script language="JavaScript">window.alert("您查询的会员信息不存在，请核对会员手机号码");</script>'; 
		echo '<script language="JavaScript">window.location.href="inputForm.php";</script>'; 
	}
	
	//var_dump($searchMobileNO);
	//var_dump($result);
	
	echo '<form>';
		while ($row=mysql_fetch_row($result))
		{
			$id_buyRecord=$row[0];
			$mobileNO=$row[1];
			$name=$row[2];
			
			$query = "SELECT * FROM pairMap WHERE mapIndex='".$row[3]."'";
			$queryresult = mysql_query($query);
			$trans = mysql_fetch_object($queryresult);			
			$sex = $trans->mapName;

			$score=$row[4]; 
			$rDomin=$row[5]; 
			$rNaked=$row[6]; 
			$rSph=$row[7]; 
			$rCyl=$row[8]; 
			$rAxis=$row[9]; 
			$rCorrect=$row[10];
			$rAdd=$row[11]; 
			$rFH=$row[12]; 
			$rPD=$row[13]; 
			$lDomin=$row[14]; 
			$lNaked=$row[15]; 			
			$lSph=$row[16]; 
			$lCyl=$row[17]; 
			$lAxis=$row[18]; 
			$lCorrect=$row[19];
			$lAdd=$row[20]; 
			$lFH=$row[21]; 
			$lPD=$row[22]; 
			$buyDate=$row[23]; 
			$comments=$row[26];
			
			$query = "SELECT * FROM pairMap WHERE mapIndex='".$row[24]."'";
			$queryresult = mysql_query($query);
			$trans = mysql_fetch_object($queryresult);		
			$shopID = $trans->mapName;
			
			$query = "SELECT * FROM pairMap WHERE mapIndex='".$row[25]."'";
			$queryresult = mysql_query($query);
			$trans = mysql_fetch_object($queryresult);		
			$optID = $trans->mapName;		
			
			echo '<hr>';
			echo '<table align="center">';
				echo '<tr align="center">';
					echo '<td>'; echo $buyDate; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo $name; echo '</td>';
					echo '<td>'; echo $sex; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo '联系电话:'; echo '</td>';
					echo '<td>'; echo $mobileNO; echo '</td>';
					echo '<td>';
					echo '<td><input type="button" value="填写回访记录" onclick="OpenInputRevisitRecordForm('.$id_buyRecord.','.$mobileNO.')"></td>';
				echo '</tr>';	
				echo '<tr><td><br></td></tr>';
				echo '<tr>';
					echo '<td>'; echo '视力方案:'; echo '</td>';
					echo '<td colspan=9>'; echo $comments; echo '</td>';
				echo '</tr>';
				// 显示该条购买记录的多条回访记录，按照时间先后顺序排列
				// var_dump($id_buyRecord);
				$exec_revisitRecord="select * from revisitRecord where id_buyRecord='".$id_buyRecord."'";
				$result_revisitRecord=mysql_query($exec_revisitRecord);
				//var_dump($id_buyRecord);
				//var_dump(mysql_num_rows($result_revisitRecord));
				if (mysql_num_rows($result_revisitRecord) >= 1)
				{				
					echo '<tr>';
						echo '<td>'; echo '回访日期'; echo '</td>';
						echo '<td>'; echo '总体评分'; echo '</td>';
						echo '<td colspan=7>'; echo '顾客反馈详情'; echo '</td>';
						echo '<td>'; echo '回访人'; echo '</td>';
					echo '</tr>';	
					while ($row_revisit=mysql_fetch_row($result_revisitRecord))
					{
						// var_dump($row_revisit);
						$revisitDate=$row_revisit[4];
						$revisitScore=$row_revisit[3];
						$feedback=$row_revisit[5];
						$revisitor=$row_revisit[6];
						$revisit_query = "SELECT * FROM pairMap WHERE mapIndex='".$revisitor."'";
						$revisit_queryresult = mysql_query($revisit_query);
						$revisit_trans = mysql_fetch_object($revisit_queryresult);		
						$revisitor = $revisit_trans->mapName;						
						echo '<tr>';
							echo '<td>'; echo $revisitDate; echo '</td>';
							echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$revisitScore.'>'; echo '</td>';
							echo '<td colspan=7>'; echo $feedback; echo '</td>';
							echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$revisitor.'>'; echo '</td>';
						echo '</tr>';
					}
				}				
				echo '<tr><td><br></td></tr>';
				echo '<tr align="center">';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo '利眼'; echo '</td>';
					echo '<td>'; echo '裸眼视力'; echo '</td>';
					echo '<td>'; echo '近视/远视'; echo '</td>';
					echo '<td>'; echo '散光'; echo '</td>';
					echo '<td>'; echo '散光轴位'; echo '</td>';
					echo '<td>'; echo '矫正视力'; echo '</td>';
					echo '<td>'; echo '下加光'; echo '</td>';
					echo '<td>'; echo '瞳高'; echo '</td>';
					echo '<td>'; echo '瞳距'; echo '</td>';
				echo '</tr>';
				echo '<tr align="center">';
					echo '<td>'; echo '右眼:'; echo '</td>';					
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rDomin.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rNaked.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rSph.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rCyl.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rAxis.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rCorrect.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rAdd.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rFH.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rPD.'>'; echo '</td>';
				echo '</tr>';	
				echo '<tr align="center">';
					echo '<td>'; echo '左眼:'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lDomin.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lNaked.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lSph.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lCyl.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lAxis.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lCorrect.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lAdd.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lFH.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lPD.'>'; echo '</td>';
				echo '</tr>';		
				echo '<tr><td><br></td></tr>';
				echo '<tr align="center">';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo '分店:'; echo '</td>';
					echo '<td>'; echo $shopID; echo '</td>';
					echo '<td>'; echo '视光师:'; echo '</td>';
					echo '<td>'; echo $optID; echo '</td>';
				echo '</tr>';		
			echo '</table>';
			echo '<hr>';
		}
	echo '</form>';
?>
<?php get_footer(); ?>